package output;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.ArrayList;
import java.util.Set;
import java.util.TreeSet;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;

public class SubCatFrame {

	public Set<Argument> arguments = new TreeSet<Argument>();
	public List<String> instances = new ArrayList<String>();
	public String status = "";
	
	/** Converts an annotated example into a subcat frame, 
	 * with all ordering relaxed. */
	
	public SubCatFrame(Example e,String fnId,String fnDistro) throws IOException, ParserConfigurationException, SAXException {
		instances.add(e.fnAnnoId);
		for (Dependent d: e.dependents) {
			// eliminate all non-Core dependents
			if (!(d.semanticRole.coreType.equals("Peripheral") || d.semanticRole.coreType.equals("Extra-Thematic"))) arguments.add(new Argument(d,fnId,e.fnAnnoId,fnDistro));
			//arguments.add(new Argument(d,fnId,e.fnAnnoId,fnDistro));
		}
		//Collections.sort(arguments);
	}
	
	public SubCatFrame() {}
	
	public String toXML() {
		String s = "      <subcatframe";
		if (!status.equals("")) s = s + " status=\"" + status + "\">\n";
		else s = s + ">\n";
		s = s + "        <arguments>\n";
		for (Argument a: arguments) {
			s = s + a.toXML();
		}
		s = s + "        </arguments>\n";		
		s = s + "        <instances>\n";
		for (String i: instances) {
			s = s + "          <instance fn-anno-id=\"" + i + "\"/>\n";
		}
		s = s + "        </instances>\n";	
		return s + "      </subcatframe>\n";
	}
	
	public SubCatFrame clone() {
		SubCatFrame f = new SubCatFrame();
		f.status = this.status;
		for (Argument a: this.arguments) {
			f.arguments.add(a.clone());
		}
		f.instances = new ArrayList<String>();
		for (String s: this.instances) {
			f.instances.add(s);
		}
		return f;
	}
	
	public SubCatFrame clone2() {
		SubCatFrame f = new SubCatFrame();
		f.status = this.status;
		for (Argument a: this.arguments) {
			f.arguments.add(a.clone2());
		}
		f.instances = new ArrayList<String>();
		for (String s: this.instances) {
			f.instances.add(s);
		}
		return f;
	}
	
	public SubCatFrame clone3() {
		SubCatFrame f = new SubCatFrame();
		f.status = this.status;
		for (Argument a: this.arguments) {
			f.arguments.add(a.clone3());
		}
		f.instances = new ArrayList<String>();
		for (String s: this.instances) {
			f.instances.add(s);
		}
		return f;
	}
	
	
	/*
	public boolean equal2(SubCatFrame f) {
		if (this.arguments.size()!=f.arguments.size()) return false;
		else {		
			for (int i=0;i<this.arguments.size();i++) {
				if (!this.arguments.get(i).equals(f.arguments.get(i))) return false;
			}
			return true;
		}
	}
	*/
	
}
